package org.jeecg.modules.operations.assistant.xcbd.service;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;

public class QRCodeService {

    public static void generateQRCode(String text, String filePath) throws WriterException, IOException {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, 200, 200);
        File file = new File(filePath);
        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", Paths.get(filePath));
        // 这里可以添加保存二维码到数据库的代码
    }
}
